/*
 *  main.cpp - console tool main
 *  Copyright (C) 2017 caryoscelus
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <iostream>
#include <fstream>

#include <fmt/ostream.h>

#include <core/document.h>
#include <core/filters/svg_path_reader.h>
#include <core/renderers/svg_renderer.h>

void render_file(std::string const& fname) {
    auto reader = core::filters::SvgPathReader();
    std::ifstream in(fname);
    std::shared_ptr<core::Document> document = reader.read_document(in);
    in.close();

    auto renderer = core::renderers::SvgRenderer();
    renderer.render(*document->get_default_context());
}

int main(int argc, char** argv) {
    std::string fname;
    if (argc < 2) {
        fmt::print(std::cerr, "Usage: {} [<file-name>]\n", argv[0]);
        return 1;
    } else {
        fname = argv[1];
    }
    render_file(fname);
    return 0;
}
